// 方式一
// 得到了一个按规则二维数组
// 时间：1012ms - 5%
function convert(s, numRows) {
  if (numRows < 2) {
    return s;
  }
  const len = s.length;
  const group = numRows + numRows - 2;
  const cols = Math.ceil(len / group) * (numRows - 1);
  let arrays = Array.from({ length: numRows }, () => {
    return Array.from(new Array(cols), () => "");
  });
  for (let n = 0; n < len; n++) {
    const z = n % group;
    const y = Math.floor(n / group);
    if (z < numRows) {
      arrays[z][(numRows - 1) * y] = s[n];
    } else {
      arrays[group - z][(y - 1) * (numRows - 1) + z] = s[n];
    }
  }
  return arrays.reduce((merge, next) => {
    return merge + next.join("");
  }, "");
}

console.log(convert("01234567890123456789", 6));
